package cc.vv.btpartyjob.partymanager.activity

import android.content.Intent
import android.text.TextUtils
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.globle.IntentJniKey
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.XingZhenCunManagerActivityDelegate
import cc.vv.btpartyjob.partymanager.inter.LookBigPicFileInterface
import cc.vv.btpartyjob.partymanager.moudel.bean.XzcSizhiDuiWuObj
import cc.vv.btpartyjob.partymanager.moudel.resp.XzcInfoResponseObj
import cc.vv.btpartyjob.partymanager.server.PartyManagerServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder
import com.dawning.utiming.task.server.SubmitJobServer

/**
 * 行政村管理
 * Created by Chen.qi on 2018/10/27.
 */
class XingZhenCunManagerActivity : BaseActivityMVP<XingZhenCunManagerActivityDelegate>(), LookBigPicFileInterface {

    private var cunId: String? = null

    private var cunName: String? = null

    private var title: String? = null

    private var picList: ArrayList<String>? = null

    override fun initData() {
        picList = ArrayList()
        JniStartActivity.startIntentCun(this, 2, 100)
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
                JniStartActivity.startIntentCun(this@XingZhenCunManagerActivity,
                        2, 100)
            }
        })

    }

    override fun getDelegateClass(): Class<XingZhenCunManagerActivityDelegate> {
        return XingZhenCunManagerActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is XzcInfoResponseObj -> {
                val data = obj.data
                title = data?.villageName
                viewDelegate?.setTopBarTitle(data?.villageName)
                viewDelegate?.setXZRenKou(data?.population)
                viewDelegate?.setXZGengDiMianJi(data?.cultivatedArea)
                viewDelegate?.setXZZhuDaoChanYe(data?.leadingIndustry)
                viewDelegate?.setXZPingKunNum(data?.povertyAlleviationNum)
                viewDelegate?.setPartyNum(data?.partyNum)
                viewDelegate?.setXZShiFouTuoPing(data?.poverty)
                val secretary = data?.secretary
                if (null != secretary) {
                    val yiList = ArrayList<XzcSizhiDuiWuObj>()
                    yiList.add(secretary)
                    viewDelegate?.setDiYiShuJiList(yiList)
                }
                viewDelegate?.setFuPingWorkList(data?.taskForceList)
                viewDelegate?.setCunLiangWeiBanZiList(data?.twoCommittee)
                viewDelegate?.setZhuCunGanBuList(data?.villageCadreList)

                picList!!.clear()
                val imgList = data?.imgList
                if (null != imgList && imgList.size > 0) {
                    (0 until imgList.size)
                            .filter { !TextUtils.isEmpty(imgList[it]) }
                            .forEach { picList!!.add(imgList[it]) }
                }
                viewDelegate?.setDangZuZhiPic(picList, this)
            }
        }
    }

    override fun lookBigImage(position: Int, type: Int) {
        SubmitJobServer.largePic(this, picList!!, position)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (null == data) {
            if (TextUtils.isEmpty(title)) {
                finish()
            }
            return
        }
        if (requestCode == 100 && resultCode == 101) {
            cunId = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_ID)
            cunName = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_NAME)
            viewDelegate?.setTopBarTitle(cunName)
            PartyManagerServer.getFuPingCunInfo(cunId)
        }
    }


}